package com.cruisecontrol4eclipse.core.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

import com.cruisecontrol4eclipse.core.PersistedData;
import com.cruisecontrol4eclipse.core.model.CruiseControlProject;
import com.cruisecontrol4eclipse.core.model.CruiseControlServer;

public class PauseBuildHandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
		if(currentSelection instanceof StructuredSelection) {
			CruiseControlProject cruiseControlProject =  (CruiseControlProject)((StructuredSelection)currentSelection).getFirstElement();
			CruiseControlServer.pauseBuild(cruiseControlProject, PersistedData.getHostname(), PersistedData.getRmiPort());
		}
		return null;
	}
}
